package com.sevattal.service.leaves.controller;


import com.sevattal.common.base.result.R;
import com.sevattal.service.leaves.entity.vo.ReturnOrderVo;
import com.sevattal.service.leaves.service.ReturnOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 归还主表 前端控制器
 * </p>
 *
 * @author Sevattal
 * @since 2021-08-28
 */
@Api(tags = "归还单管理")
@RestController
@RequestMapping("/admin/leaves/return-order")
public class ReturnOrderController {

    @Autowired
    private ReturnOrderService returnOrderService;


    @ApiOperation("新建归还单")
    @PostMapping("createReturnOrder")
    public R createReturnOrder(@ApiParam(value = "归还单对象",required = true) @RequestBody ReturnOrderVo returnOrderVo){
        boolean result = returnOrderService.createReturnOrder(returnOrderVo);
        if (result) {
            return R.ok().message("创建成功");
        }else{
            return R.error().message("创建失败");
        }
    }

    @ApiOperation("修改归还单")
    @PutMapping("updateReturnOrder")
    public R updateReturnOrder(@ApiParam(value = "申领单主表对象",required = true) @RequestBody  ReturnOrderVo returnOrderVo) {
        boolean result = returnOrderService.updateReturnOrder(returnOrderVo);
        if (result) {
            return R.ok().message("修改成功");
        }else{
            return R.error().message("修改失败");
        }
    }

    @ApiOperation("删除归还单")
    @DeleteMapping("deleteApplyOrder/{id}")
    public R deleteReturnOrder(@ApiParam(value = "供应商id",required = true) @PathVariable String id) {
        boolean result = returnOrderService.deleteReturnOrder(id);
        if (result) {
            return R.ok().message("删除成功");
        }else{
            return R.error().message("删除失败");
        }
    }

    @ApiOperation("获取归还单信息")
    @PostMapping("getReturnOrderList")
    public R getReturnOrderList(@ApiParam(value = "供应商对象",required =  true)  @RequestBody ReturnOrderVo returnOrderVo){
        List<ReturnOrderVo> returnOrderList = returnOrderService.getReturnOrderList(returnOrderVo);
        return R.ok().data("returnOrderList",returnOrderList);
    }
}

